<?php 
namespace Admin\Model;
use Think\Model;
class CatModel extends Model{
	public $cats = array();

	public function __construct(){
		parent::__construct();
		$this->cats = $this->cache(true)->select();
	}

	public function getTree($parent_id=0, $len=0){
		$tree = array();
		foreach($this->cats as $v){
			if($v['parent_id'] == $parent_id){
				$v['len'] = $len;
				$tree[] = $v;

				$tree = array_merge($tree,$this->getTree($v['cat_id'],$len+1));
			}
		}

		return $tree;
	}
}